package org.easy.web.service.socket.impl;

import org.easy.socket.client.EasyClient;
import org.easy.socket.client.config.ClientConfig;
import org.easy.socket.client.mamager.IOperator;
import org.easy.web.service.socket.SocketService;
import org.springframework.stereotype.Service;

/**
 * @Description:
 * @Author: wxl
 * @CreateTime: 2023/1/12 11:40
 */
@Service
public class SocketServiceImpl implements SocketService {

    private IOperator operator;

    /**
     * 连接到服务端
     */
    @Override
    public void connectedToServer() {
        ClientConfig config = new ClientConfig("127.0.0.1",8000);
        this.operator = new EasyClient(config);
        this.operator.setStartHeart(true);
        operator.start();
    }

    /**
     * 发送消息
     *
     * @param msg 消息
     */
    @Override
    public void sendMsg(String msg) {
        this.operator.send(msg);
    }

    /**
     * 断开连接
     */
    @Override
    public void close() {
        this.operator.close();
    }
}
